﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Common.Library;
using Microsoft.Advertising.Mobile.UI;
using OnlineVideos.Library;
using OnlineVideos.Common;
using OnlineVideos.UI;
using OnlineVideos.Data;

using Common;
using Common.Utilities;
using OnlineVideos.Entities;

namespace OnlineVideos.Views
{
    public partial class SongsList : PhoneApplicationPage
    {
        #region Global
        string id = "";
        List<ShowLinks> objsonglist = new List<ShowLinks>();
        #endregion

        #region Constructor
        public SongsList()
        {
            InitializeComponent();
            tblkVideosTitle.Text = OnlineShow.GetShowDetail(long.Parse(AppSettings.ShowID)).Title;
        }
        #endregion

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.EndTimedEvent("SongsList Page");
            }
            catch (Exception ex)
            {

               Exceptions.SaveOrSendExceptions("Exception in OnNavigatedFrom event In SongsList.cs file.", ex);
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.LogPageView();
            }
            catch (Exception ex)
            {
                
                  Exceptions.SaveOrSendExceptions("Exception in OnNavigatedTo event In SongsList.cs file.", ex);
            }
        }
        #region PageLoad
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
           
            LoadAds();
               
            try
            {
                FlurryWP8SDK.Api.LogEvent("SongsList Page", true);
            if (NavigationContext.QueryString.TryGetValue("mid", out id))
            {
                objsonglist = OnlineShow.GetRemoveShowList(id);
              if (objsonglist.Count > 0)
              {
                  lbxRemoveList.ItemsSource = objsonglist;
                  tblkNoSongs.Visibility = Visibility.Collapsed;
              }
              else
              {
                  tblkNoSongs.Visibility = Visibility.Visible;
                  tblkNoSongs.Text = "No " + Application.Current.Resources["pvtFHStitlesTwo"] as string + " available";
              }

                }
            }
            catch (Exception ex)
            {

                 Exceptions.SaveOrSendExceptions("Exception in PhoneApplicationPage_Loaded event In SongsList.cs file.", ex);
            }
        }
        #endregion

        #region Events
        private void LoadAds()
        {
            try
            {
                PageHelper.LoadAdControl(LayoutRoot, adstackpl, 2);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in LoadAds Method In SongDetails file", ex);
                string excepmess = "Exception in LoadAds Method In SongDetails file.\n\n" + ex.Message + "\n\n StackTrace :- \n" + ex.StackTrace;
            }

        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
            ListBoxItem selectedListBoxItem = this.lbxRemoveList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;
            if (selectedListBoxItem == null)
                return;
            string ChapterNo = (selectedListBoxItem.Content as ShowLinks).LinkOrder.ToString();
            OnlineShow.SaveRemoveSongs(id, ChapterNo);

            lbxRemoveList.ItemsSource = OnlineShow.GetRemoveShowList(id); 
        }
            catch (Exception ex)
            {
                
               Exceptions.SaveOrSendExceptions("Exception in MenuItem_Click event In SongsList.cs file.", ex);
            }
        }
        private void imgTitle_MouseEnter(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(NavigationHelper.MainPanoramaPage);
        }
        #endregion

        

    }
}